<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>
<script type="text/javascript">
	var add_form_panel = Ext.create("Ext.form.Panel", {
		url : "add.htm",
		buttonAlign : "center",
		bodyStyle : "padding: 10px;",
		width : 500,
		defaultType : "textfield",
		items : [ {
			name : "loc.kid",
			hidden : true
		}, {
			fieldLabel : "父节点",
			name : "up_node",
			readOnly : true
		}, {
			xtype : "fieldcontainer",
			fieldLabel : "编号",
			layout : "hbox",
			items : [ {
				width : 100,
				xtype : "textfield",
				id : "up_code",
				name : "up_code",
				readOnly : true
			}, {
				width : 80,
				xtype : "textfield",
				name : "loc.code",
				allowBlank : false,
				minLength : 3,
				maxLength : 3,
				validator : function() {
					var error = true;
					Ext.Ajax.request({
						url : 'auth_unique.htm',
						params : {
							code : Ext.getCmp("up_code").getValue() + this.value
						},
						scope : true,
						async : false,
						method : 'POST',
						success : function(response) {
							var result = Ext.JSON.decode(response.responseText);
							if ("true" == result.fail) {
								error = "该编号己经存在,请重新输入！";
							}
						}
					});
					return error;
				}//end_validator  
			} ]
		}, {
			fieldLabel : "名称",
			name : "loc.name",
			allowBlank : false
		}, {
			xtype : "radiogroup",
			fieldLabel : "类型",
			width : 300,
			items : [ {
				name : "loc.type",
				boxLabel : "省",
				inputValue : "省",
				checked : true
			}, {
				name : "loc.type",
				boxLabel : "市",
				inputValue : "市"
			}, {
				name : "loc.type",
				boxLabel : "县",
				inputValue : "县"
			}, {
				name : "loc.type",
				boxLabel : "镇",
				inputValue : "镇"
			}, {
				name : "loc.type",
				boxLabel : "乡",
				inputValue : "乡"
			}, {
				name : "loc.type",
				boxLabel : "国",
				inputValue : "国"
			} ]
		} ],
		buttons : [ {
			text : "保存",
			formBind : true, //only enabled once the form is valid
			disabled : true,
			handler : function() {
				var form = this.up("form").getForm();
				if (form.isValid()) {
					form.submit({
						waitMsg : "保存中...",
						success : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
							add_form_panel_win.close();
							dataStore.load();
						},
						failure : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
						}
					});
				}
			}
		} ]
	});

	var add_form_panel_win = Ext.create("Ext.Window", {
		title : "地区添加",
		closeAction : "hide",
		items : add_form_panel
	});

	function myAdd(up_code, up_name) {
		add_form_panel.getForm().reset();
		add_form_panel.getForm().setValues({
			"up_node" : up_name + "[" + up_code + "]",
			"up_code" : up_code
		});

		add_form_panel_win.show();
	}
</script>
